﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Data;
using System.Drawing;
using System.Text;

using FCNS.KeepMoneyLibrary.Util;

namespace FCNS.KeepMoneyLibrary.Data
{
    public class GtdGroupField
    {
        public void Remove()
        {
            foreach (DataRow row in KMData.DataTableGtdEntrys.Select("GtdGroupId = " + Id))
                KMData.DataTableGtdEntrys.Rows.Remove(row);

            KMData.DataTableGtdGroups.Rows.Remove(dRow);
            fields.Remove(this);
        }

        static List<GtdGroupField> fields = new List<GtdGroupField>();
        public static List<GtdGroupField> GetGtdGroupField
        {
            get
            {
                if (fields.Count == 0)
                    foreach (DataRow row in KMData.DataTableGtdGroups.Rows)
                        fields.Add(new GtdGroupField(row));

                return fields;
            }
        }

        bool add = false;
        public void AddRowToDataTable()
        {
            if (!add)
                return;

            KMData.DataTableGtdGroups.Rows.Add(dRow);
            fields.Add(this);
            add = false;
        }


        DataRow dRow = null;
        public GtdGroupField(DataRow row)
        {
            dRow = row;
            GetColor(Color);
        }

        public GtdGroupField(GtdColor color)
        {
            dRow = KMData.DataTableGtdGroups.NewRow();
            add = true;
            Color = color;
        }

        public int Id
        {
            get { return (int)dRow["Id"]; }
            set { dRow["Id"] = value; }
        }

        public string Name
        {
            get { return (string)dRow["Name"]; }
            set { dRow["Name"] = value; }
        }

        public bool Checked
        {
            get { return (bool)dRow["Checked"]; }
            set { dRow["Checked"] = value; }
        }

        public GtdColor Color
        {
            get { return (GtdColor)dRow["Color"]; }
            set { dRow["Color"] = (int)value; }
        }

        private void GetColor(GtdColor color)
        {
            switch (color)
            {
                case GtdColor.蓝色:
                    colorBorder = System.Drawing.Color.FromArgb(255, 0, 81, 212);
                    colorText = System.Drawing.Color.FromArgb(255, 255, 255, 255);
                    colorBgUnselected = System.Drawing.Color.FromArgb(200, 141, 181, 242);
                    colorBgSelectedLeft = System.Drawing.Color.FromArgb(255, 28, 104, 224);
                    colorBgSelectedRight = System.Drawing.Color.FromArgb(255, 90, 149, 245);
                    break;
                case GtdColor.橙色:
                    colorBorder = System.Drawing.Color.FromArgb(255, 245, 118, 0);
                    colorText = System.Drawing.Color.FromArgb(255, 255, 255, 255);
                    colorBgUnselected = System.Drawing.Color.FromArgb(200, 245, 211, 180);
                    colorBgSelectedLeft = System.Drawing.Color.FromArgb(255, 247, 129, 17);
                    colorBgSelectedRight = System.Drawing.Color.FromArgb(255, 255, 164, 79);
                    break;
                case GtdColor.蔷薇色:
                    colorBorder = System.Drawing.Color.FromArgb(255, 176, 39, 174);
                    colorText = System.Drawing.Color.FromArgb(255, 255, 255, 255);
                    colorBgUnselected = System.Drawing.Color.FromArgb(200, 232, 171, 232);
                    colorBgSelectedLeft = System.Drawing.Color.FromArgb(255, 186, 67, 184);
                    colorBgSelectedRight = System.Drawing.Color.FromArgb(255, 196, 90, 196);
                    break;
                case GtdColor.珊瑚红:
                    colorBorder = System.Drawing.Color.FromArgb(255, 230, 23, 23);
                    colorText = System.Drawing.Color.FromArgb(255, 255, 255, 255);
                    colorBgUnselected = System.Drawing.Color.FromArgb(200, 251, 171, 171);
                    colorBgSelectedLeft = System.Drawing.Color.FromArgb(255, 244, 44, 44);
                    colorBgSelectedRight = System.Drawing.Color.FromArgb(255, 250, 97, 97);
                    break;
                case GtdColor.紫罗兰:
                    colorBorder = System.Drawing.Color.FromArgb(255, 73, 43, 161);
                    colorText = System.Drawing.Color.FromArgb(255, 255, 255, 255);
                    colorBgUnselected = System.Drawing.Color.FromArgb(200, 195, 183, 233);
                    colorBgSelectedLeft = System.Drawing.Color.FromArgb(255, 92, 64, 176);
                    colorBgSelectedRight = System.Drawing.Color.FromArgb(255, 171, 149, 237);
                    break;
                default:
                    colorBorder = System.Drawing.Color.FromArgb(255, 44, 161, 11);
                    colorText = System.Drawing.Color.FromArgb(255, 255, 255, 255);
                    colorBgUnselected = System.Drawing.Color.FromArgb(200, 158, 241, 136);
                    colorBgSelectedLeft = System.Drawing.Color.FromArgb(255, 68, 173, 38);
                    colorBgSelectedRight = System.Drawing.Color.FromArgb(255, 113, 194, 91);
                    break;
            }
        }

        Color colorBorder, colorText, colorBgUnselected, colorBgSelectedLeft, colorBgSelectedRight;
        /// <summary>
        /// 获取日历任务栏目的填充颜色
        /// </summary>
        public Color ColorBorder
        {
            get
            {
                return colorBorder;
            }
        }
        /// <summary>
        /// 获取日历任务栏目的文本颜色
        /// </summary>
        public Color ColorText
        {
            get
            {
                return colorText;
            }
        }
        /// <summary>
        /// 获取日历任务栏目未选择状态的背景颜色
        /// </summary>
        public Color ColorBgUnselected
        {
            get
            {
                return colorBgUnselected;
            }
        }
        /// <summary>
        /// 获取日历任务栏目选择状态的左背景颜色
        /// </summary>
        public Color ColorBgSelectedLeft
        {
            get
            {
                return colorBgSelectedLeft;
            }
        }
        /// <summary>
        /// 获取日历任务栏目选择状态的右背景颜色
        /// </summary>
        public Color ColorBgSelectedRight
        {
            get
            {
                return colorBgSelectedRight;
            }
        }
    }
}
